package com.garen.orm.biz.impl;

import java.util.*;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.garen.orm.ConvertColumn;
import com.garen.orm.ConvertInfo;
import com.garen.orm.biz.IOrmBiz;
import com.garen.orm.dao.IOrmDao;

@Service
public class OrmBizImpl implements IOrmBiz {

	private static Log log = LogFactory.getLog(OrmBizImpl.class);   
	
	
	@Resource(name="ormmetadao")
	private IOrmDao ormdao;
	
	@Override
	public List<String> getTables() {
		return ormdao.getTables();
	}
	
	//转换
	public int convert(List<ConvertInfo> infolist){
		//遍历表
		for(ConvertInfo info : infolist){
			info.convert();//表转换
			Set<ConvertColumn> collist = ormdao.getColumnInfo(info.getTableName());
			info.setColist(collist);
			log.debug("包名：" + info.getPackName() + ",表名：" + info.getTableName()
					+ ",类名：" + info.getClassName());
		}
		saveOrmFile(infolist);
		return 0;
	}
			
	//保存
	private void saveOrmFile(List<ConvertInfo> infolist){
		//遍历表
		for(ConvertInfo info : infolist){
			AutoCreateClass acc = new AutoCreateClass(info);
			acc.saveEntityClass();
			acc.saveDaoClass();
			acc.saveIBizClass();
			acc.saveBizClass();
			acc.saveIDaoClass();
			acc.saveActionClass();
			//acc.saveJspView();
			//acc.saveEditJspView();
			acc.saveJavaScript();
		}
	}

}
